# -*- coding: utf-8 -*-
import re
import os.path
import tenjin
from tenjin.helpers import *
from setting import *

try:
    import tornado
except:
    pass


###
engine = tenjin.Engine(path=[os.path.join(['templates'], cache=tenjin.MemoryCacheStorage(), preprocess=True)
class BaseHandler(tornado.web.RequestHandler):
            
    def render(self, template, context=None, globals=None, layout=False):
        if context is None:
            context = {}
        context.update({
            'request':self.request,
        })
        return engine.render(template, context, globals, layout)

    def echo(self, template, context=None, globals=None, layout=False):
        self.write(self.render(template, context, globals, layout))    